<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：链表问题一版都是定义一个虚拟头节点，然后定义指针遍历
      */
      var removeElements = function (head, val) {
        let dummy = new ListNode(0, head)
        let pre = dummy
        let cur = head
        while (cur) {
          if (cur.val == val) {
            // 1 2 3
            let next = cur.next
            pre.next = next
            cur = next
          } else {
            pre = cur
            cur = cur.next
          }
        }
        return dummy.next
      }
    </script>
  </body>
</html>
